home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / mail / xmailbox.4-s / xmailbox / xmailbox-2.4 / xmailbox.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-01  |  4.0 KB  |  121 lines

  1. /*
  2.  * Copyright (c) 1994-96  Dimitrios P. Bouras and William K. W. Cheung
  3.  * 
  4.  * Permission is hereby granted, free of charge, to any person obtaining a copy
  5.  * of this software and associated documentation files (the "Software"), to deal
  6.  * in the Software without restriction, including without limitation the rights
  7.  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8.  * copies of the Software, and to permit persons to whom the Software is
  9.  * furnished to do so, subject to the following conditions:
  10.  * 
  11.  * The above copyright notice and this permission notice shall be included in
  12.  * all copies or substantial portions of the Software.
  13.  * 
  14.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
  17.  * X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  18.  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  19.  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20.  * 
  21.  * Except as contained in this notice, the name of the X Consortium shall not be
  22.  * used in advertising or otherwise to promote the sale, use or other dealings
  23.  * in this Software without prior written authorization from the X Consortium.
  24.  * 
  25.  * Derived from the MIT X11R5 xbiff, written by Jim Fulton, which is
  26.  * copyrighted (c) 1988 X Consortium.
  27.  *
  28.  * xmailbox XPM additions-modifications: Dimitrios P. Bouras
  29.  * Audio support and XPM icon animation: William K. W. Cheung
  30.  */
  31.  
  32. #include <stdio.h>
  33. #include <X11/Xatom.h>
  34. #include <X11/Intrinsic.h>
  35. #include <X11/StringDefs.h>
  36. #include "Mailbox.h"
  37. #include <X11/Xaw/Cardinals.h>
  38.  
  39. extern void exit();
  40. static void quit();
  41.  
  42. char *ProgramName;
  43.  
  44. static XrmOptionDescRec options[] = {
  45. { "-update", "*mailbox.update", XrmoptionSepArg, (caddr_t) NULL },
  46. { "-file",   "*mailbox.file", XrmoptionSepArg, (caddr_t) NULL },
  47. { "-volume", "*mailbox.volume", XrmoptionSepArg, (caddr_t) NULL },
  48. };
  49.  
  50. static XtActionsRec xmailbox_actions[] = {
  51.     { "quit", quit }
  52. };
  53. static Atom wm_delete_window;
  54.  
  55. static void Usage ()
  56. {
  57.     static char *help_message[] = {
  58. "where options include:",
  59. "    -display host:dpy              X server to contact",
  60. "    -geometry geom                 position of mailbox",
  61. "    -file file                     file to watch",
  62. "    -update seconds                how often to check for mail",
  63. "    -volume percentage             how loud to ring the bell or play sound",
  64. NULL};
  65.     char **cpp;
  66.  
  67.     fprintf (stderr, "usage:  %s [-options ...]\n", ProgramName);
  68.     for (cpp = help_message; *cpp; cpp++) {
  69.     fprintf (stderr, "%s\n", *cpp);
  70.     }
  71.     fprintf (stderr, "\n");
  72.     exit (1);
  73. }
  74.  
  75.  
  76. void main (argc, argv)
  77.     int argc;
  78.     char **argv;
  79. {
  80.     XtAppContext xtcontext;
  81.     Widget toplevel, w;
  82.  
  83.     ProgramName = argv[0];
  84.  
  85.     toplevel = XtAppInitialize(&xtcontext, "XMailbox", options, XtNumber (options),
  86.                    &argc, argv, NULL, NULL, 0);
  87.     if (argc != 1) Usage ();
  88.  
  89.     /*
  90.      * This is a hack so that f.delete will do something useful in this
  91.      * single-window application.
  92.      */
  93.     XtAppAddActions (xtcontext, xmailbox_actions, XtNumber(xmailbox_actions));
  94.     XtOverrideTranslations(toplevel,
  95.            XtParseTranslationTable ("<Message>WM_PROTOCOLS: quit()"));
  96.  
  97.     w = XtCreateManagedWidget ("mailbox", mailboxWidgetClass, toplevel,
  98.                    NULL, 0);
  99.     XtRealizeWidget (toplevel);
  100.     wm_delete_window = XInternAtom (XtDisplay(toplevel), "WM_DELETE_WINDOW",
  101.                                     False);
  102.     (void) XSetWMProtocols (XtDisplay(toplevel), XtWindow(toplevel),
  103.                             &wm_delete_window, 1);
  104.     XtAppMainLoop (xtcontext);
  105. }
  106.  
  107. static void quit (w, event, params, num_params)
  108.     Widget w;
  109.     XEvent *event;
  110.     String *params;
  111.     Cardinal *num_params;
  112. {
  113.     if (event->type == ClientMessage &&
  114.         event->xclient.data.l[0] != wm_delete_window) {
  115.         XBell (XtDisplay(w), 0);
  116.         return;
  117.     }
  118.     XCloseDisplay (XtDisplay(w));
  119.     exit (0);
  120. }
  121.